package com.lbiuse.biz.manage.user.service;

import com.lbiuse.biz.manage.user.dao.UserDAO;
import org.apache.commons.lang.StringUtils;
import org.bidtime.utils.crypt.AESUtils;
import org.bidtime.web.utils.RequestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
import java.util.*;




@Service
public class UserService {
	
	
	@Autowired
	private UserDAO dao;
	/*@Autowired
	private ShopUserDAO shopUserDao;
	@Autowired
	private UserDutyDao userDutyDao;*/

	
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly=true)
	public   List<Object> getCsvDown(HttpServletRequest request) throws Exception {
		/*
		Map<String, Object> params = new HashMap<String, Object>();
		String mp = (String) RequestUtils.getString(request, "phone");
		if(StringUtils.isNotEmpty(mp)){
			mp = AESUtils.getInst().encrypt(mp);
		}
		params.put("mp", mp);
		params.put("status", RequestUtils.getString(request, "status"));
		params.put("shopId", RequestUtils.getString(request, "shopId"));
		
		
		GsonHeadManyRows  g= dao.getUserListAll( params);
			
		if(g==null){
			return null;
		}
		List<Object> result=new ArrayList<Object>();
		
		 LinkedHashMap<String,Object> map = new LinkedHashMap<String,Object>();//都出数据的头
	        map.put("1", "姓名");
	        map.put("2", "登陆名");
	        map.put("3", "性别");
	        map.put("4", "身份证");
	        map.put("5", "地址");
	        map.put("6", "电话");
	        map.put("7", "手机");
	        map.put("8", "Email");
	        map.put("9", "邮编");
	        map.put("10", "部门");
	        map.put("11", "状态");
	        map.put("12", "建档时间");
	       result.add(map) ;
	       
	       List<Map<String,Object>> exportData = new ArrayList<Map<String,Object>>();
	       
	       	for (int i = 0; i < g.getDataLength(); i++) {
	       		Map<String,Object> row = new LinkedHashMap<String, Object>();
	       		String Name=	(String) g.getValueOfName("Name", i);
	       		String LoginName =(String)g.getValueOfName("LoginName", i);
	       		String Sex =(String) g.getValueOfName("Sex", i);
	       		String IDNumber =(String) g.getValueOfName("IDNumber", i);
	       		String Address =(String) g.getValueOfName("Address", i);
	       		String Tel=ObjectComm.objectToString(g.getValueOfName("Tel", i));
	       		String Mp=ObjectComm.objectToString(g.getValueOfName("Mp", i));
	       		String Email=ObjectComm.objectToString(g.getValueOfName("Email", i));
	       		String ZipCode=ObjectComm.objectToString(g.getValueOfName("ZipCode", i));
	       		String StatusName=ObjectComm.objectToString(g.getValueOfName("StatusName", i));
	       		Date CreateFileTime=(Date)(g.getValueOfName("CreateFileTime", i));
			
			row.put("1", Name==null?" ":Name);
			row.put("2", LoginName==null?" ":LoginName);
			row.put("3", Sex==null?" ":Sex);
			row.put("4", mp==null?" ":mp);
			row.put("5", IDNumber==null?" ":IDNumber);
			row.put("6", Address==null?" ": Address);
			row.put("7", Tel==null?" ":Tel);
			row.put("8", Mp==null?" ":Mp);
			row.put("9", Email==null?" ":Email);
			row.put("10", ZipCode==null?" ":ZipCode);
			row.put("11", StatusName==null?" ":StatusName);
			
			row.put("12", CreateFileTime==null?" ":CDateTimeComm.dateToyyyyMMddHHmmss(CreateFileTime));

			exportData.add(row);
			} 
			result.add(exportData);	

		return result;
	*/
	return null;

	}


	/*@Transactional(rollbackFor = Exception.class)
	public Long insertInfo(ParserDataSetJson up, ParserDataSetJson sp,
			ParserDataSetJson pp,String html) throws SQLException {
		int result=0;
		Long userId = (long) 0;
		result= dao.applyUpdates(up,"id");
		if(result>0){
			userId= (Long) up.getListInsertRows().get(0).getValueOfName("id");
			for (int i = 0; i < sp.getListInsertRows().size(); i++) {
				sp.getListInsertRows().get(i).addHeadData("CustId", userId);
			}
			shopUserDao.applyUpdates(sp);
			for (int i = 0; i < pp.getListInsertRows().size(); i++) {
				pp.getListInsertRows().get(i).addHeadData("custId", userId);
			}
			userDutyDao.applyUpdates(pp);
			
			String srvUrl =GlobalParams
					.getGlobalParams().getApacheUrl()+HtmlUtilsConst.PATH_HTML+"user"+"/"+userId+"/";
					String rootPath = GlobalParams.getGlobalParams().getApacheRoot()+HtmlUtilsConst.PATH_HTML+"user"+"/"+userId+"/";
					if (StringUtils.isNotEmpty(html)) {
					 StrToHtmlUtils.getWriteRsult(html, srvUrl, rootPath, "user", "人员");
					 dao.updateIndex(srvUrl+"user.html", userId.toString());
					}
		}
		return userId;
	}

	@Transactional(rollbackFor = Exception.class)
	public int updateInfo(ParserDataSetJson up, ParserDataSetJson sp,
			ParserDataSetJson pp, String html) throws SQLException {
			dao.applyUpdates(up);
			shopUserDao.applyUpdates(sp);
			userDutyDao.applyUpdates(pp);
			String userId= ObjectComm.objectToString(up.getListUpdateRows().get(0).getValueOfName("id"));
			String srvUrl =GlobalParams
					.getGlobalParams().getApacheUrl()+HtmlUtilsConst.PATH_HTML+"user"+"/"+userId+"/";
					String rootPath = GlobalParams.getGlobalParams().getApacheRoot()+HtmlUtilsConst.PATH_HTML+"user"+"/"+userId+"/";
					if (StringUtils.isNotEmpty(html)) {
					 StrToHtmlUtils.getWriteRsult(html, srvUrl, rootPath, "user", "人员");
					 dao.updateIndex(srvUrl+"user.html", userId);
					}
		return 1;
	}*/
	}
